package com.yunpeng.aidevice.common.controllers;

import com.yunpeng.aidevice.biz.service.IDeviceDataCenterBizService;
import com.yunpeng.aidevice.common.constant.ConfigConstantValues;
import com.yunpeng.common.dto.Result;
import com.yunpeng.aidevice.common.dto.cache.LoginUserCacheDTO;
import com.yunpeng.aidevice.common.dto.query.*;
import com.yunpeng.common.paging.PagingQueryDTO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * DataCenterController
 *
 * @author : Moore(hemw)
 * @date : 2020-04-28
 */
@RestController
@RequestMapping("/api/dataCenter")
public class DataCenterController {

    @Resource
    private IDeviceDataCenterBizService deviceDataCenterBizService;


    /**
     * 设备单日详情数据
     *
     * @param deviceDayDetailQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "deviceDayRecordDetail", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryDeviceDayRecordDetail(@RequestBody DeviceDayDetailQueryDTO deviceDayDetailQueryDTO) {
        if (deviceDayDetailQueryDTO == null) {
            deviceDayDetailQueryDTO = new DeviceDayDetailQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        deviceDayDetailQueryDTO.setMerchantCode(loginUserCacheDTO.getMerchantCode());
        deviceDayDetailQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryDeviceDayRecordDetail(deviceDayDetailQueryDTO);
    }


    /**
     * 统计单日设备通行数据
     *
     * @param deviceDayCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "deviceDayRecordCount", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryDeviceDayCount(@RequestBody DeviceDayCountQueryDTO deviceDayCountQueryDTO) {
        if (deviceDayCountQueryDTO == null) {
            deviceDayCountQueryDTO = new DeviceDayCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        deviceDayCountQueryDTO.setMerchantCode(loginUserCacheDTO.getMerchantCode());
        deviceDayCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryDeviceDayCount(deviceDayCountQueryDTO);
    }


    /**
     * 统计多日设备通行数据
     *
     * @param deviceDaysCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "deviceDateRecordCount", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryDeviceDateRecordCount(@RequestBody DeviceDaysCountQueryDTO deviceDaysCountQueryDTO) {
        if (deviceDaysCountQueryDTO == null) {
            deviceDaysCountQueryDTO = new DeviceDaysCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        deviceDaysCountQueryDTO.setMerchantCode(loginUserCacheDTO.getMerchantCode());
        deviceDaysCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryDeviceDateRecordCount(deviceDaysCountQueryDTO);
    }

    /**
     * 统计组织多日设备通行数据
     *
     * @param deviceOrgDaysCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "orgRecordCount", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryOrgDeviceDayCount(@RequestBody DeviceOrgDaysCountQueryDTO deviceOrgDaysCountQueryDTO) {
        if (deviceOrgDaysCountQueryDTO == null) {
            deviceOrgDaysCountQueryDTO = new DeviceOrgDaysCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        deviceOrgDaysCountQueryDTO.setMerchantCode(loginUserCacheDTO.getMerchantCode());
        deviceOrgDaysCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryOrgDeviceDayCount(deviceOrgDaysCountQueryDTO);
    }

    /**
     * 统计用户设备通行数据
     *
     * @param userDeviceDaysCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "userRecordCountView", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryUserDeviceDayCountView(@RequestBody UserDeviceDaysCountQueryDTO userDeviceDaysCountQueryDTO) {
        if (userDeviceDaysCountQueryDTO == null) {
            userDeviceDaysCountQueryDTO = new UserDeviceDaysCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        userDeviceDaysCountQueryDTO.setMerchantCode(loginUserCacheDTO.getMerchantCode());
        userDeviceDaysCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryUserDeviceDayCountView(userDeviceDaysCountQueryDTO);
    }


    /**
     * 组织设备日统计数据
     *
     * @param orgDeviceDaysCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "orgRecordCountView", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryOrgDeviceDayCountView(@RequestBody OrgDeviceDaysCountQueryDTO orgDeviceDaysCountQueryDTO) {
        if (orgDeviceDaysCountQueryDTO == null) {
            orgDeviceDaysCountQueryDTO = new OrgDeviceDaysCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        orgDeviceDaysCountQueryDTO.setMerchantCode(loginUserCacheDTO.getMerchantCode());
        orgDeviceDaysCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryOrgDeviceDayCountView(orgDeviceDaysCountQueryDTO);
    }


    /**
     * 商户设备日统计数据
     *
     * @param merchantDeviceCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "merchantRecordCount", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryMerchantDeviceDayCount(@RequestBody MerchantDeviceCountQueryDTO merchantDeviceCountQueryDTO) {
        if (merchantDeviceCountQueryDTO == null) {
            merchantDeviceCountQueryDTO = new MerchantDeviceCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        merchantDeviceCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryMerchantDeviceDayCount(merchantDeviceCountQueryDTO);
    }

    /**
     * 商户设备汇总
     *
     * @param merchantDeviceCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "merchantDeviceRecordCount", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryMerchantDeviceDaysRecordCount(@RequestBody MerchantDeviceCountQueryDTO merchantDeviceCountQueryDTO) {
        if (merchantDeviceCountQueryDTO == null) {
            merchantDeviceCountQueryDTO = new MerchantDeviceCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        merchantDeviceCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryMerchantDeviceDaysRecordCount(merchantDeviceCountQueryDTO);
    }
    
    /**
     * 商户体温走势
     *
     * @param merchantDeviceCountQueryDTO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "merchantRecordCountView", method = RequestMethod.POST)
    public Result<PagingQueryDTO> queryMerchantRecordCountView(@RequestBody MerchantDeviceCountQueryDTO merchantDeviceCountQueryDTO) {
        if (merchantDeviceCountQueryDTO == null) {
            merchantDeviceCountQueryDTO = new MerchantDeviceCountQueryDTO();
        }
        LoginUserCacheDTO loginUserCacheDTO = ConfigConstantValues.getLoginUserCacheDTO();
        merchantDeviceCountQueryDTO.setTenantCode(loginUserCacheDTO.getTenantCode());
        return deviceDataCenterBizService.queryMerchantRecordCountView(merchantDeviceCountQueryDTO);
    }
}
